home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 62 / Quick PC 62.iso / Programs / Virtual.CD.v5.0.2.Network.Edition.WinALL / VCD502EG.exe / Program Files / Virtual CD v5 / API / examples / MFC / VcdAPITest / VcdAPITestDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-19  |  9.3 KB  |  393 lines

  1. // VcdAPITestDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "VcdAPITest.h"
  6. #include "VcdAPITestDlg.h"
  7. #include "DlgSetDrives.h"
  8. #include "DlgAskVCD.h"
  9.  
  10. // Virtual CD API
  11. #include "vcdapidefs.h"
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CAboutDlg dialog used for App About
  21.  
  22. class CAboutDlg : public CDialog
  23. {
  24. public:
  25.     CAboutDlg();
  26.  
  27. // Dialog Data
  28.     //{{AFX_DATA(CAboutDlg)
  29.     enum { IDD = IDD_ABOUTBOX };
  30.     //}}AFX_DATA
  31.  
  32.     // ClassWizard generated virtual function overrides
  33.     //{{AFX_VIRTUAL(CAboutDlg)
  34.     protected:
  35.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  36.     //}}AFX_VIRTUAL
  37.  
  38. // Implementation
  39. protected:
  40.     //{{AFX_MSG(CAboutDlg)
  41.     //}}AFX_MSG
  42.     DECLARE_MESSAGE_MAP()
  43. };
  44.  
  45. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  46. {
  47.     //{{AFX_DATA_INIT(CAboutDlg)
  48.     //}}AFX_DATA_INIT
  49. }
  50.  
  51. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  52. {
  53.     CDialog::DoDataExchange(pDX);
  54.     //{{AFX_DATA_MAP(CAboutDlg)
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  59.     //{{AFX_MSG_MAP(CAboutDlg)
  60.         // No message handlers
  61.     //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CVcdAPITestDlg dialog
  66.  
  67. CVcdAPITestDlg::CVcdAPITestDlg(CWnd* pParent /*=NULL*/)
  68.     : CDialog(CVcdAPITestDlg::IDD, pParent)
  69. {
  70.     //{{AFX_DATA_INIT(CVcdAPITestDlg)
  71.     m_bVCDDebug = FALSE;
  72.     //}}AFX_DATA_INIT
  73.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  74.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  75. }
  76.  
  77. void CVcdAPITestDlg::DoDataExchange(CDataExchange* pDX)
  78. {
  79.     CDialog::DoDataExchange(pDX);
  80.     //{{AFX_DATA_MAP(CVcdAPITestDlg)
  81.     DDX_Check(pDX, IDC_VCDDEBUG, m_bVCDDebug);
  82.     //}}AFX_DATA_MAP
  83. }
  84.  
  85. BEGIN_MESSAGE_MAP(CVcdAPITestDlg, CDialog)
  86.     //{{AFX_MSG_MAP(CVcdAPITestDlg)
  87.     ON_WM_SYSCOMMAND()
  88.     ON_WM_PAINT()
  89.     ON_WM_QUERYDRAGICON()
  90.     ON_BN_CLICKED(IDC_GETVCDDRIVELETTERS, OnGetvcddriveletters)
  91.     ON_BN_CLICKED(IDC_VCDDEBUG, OnVcddebug)
  92.     ON_BN_CLICKED(IDC_GETVCDFILEFROMDRIVE, OnGetvcdfilefromdrive)
  93.     ON_BN_CLICKED(IDC_VCDEJECT, OnVcdeject)
  94.     ON_BN_CLICKED(IDC_GETVCDLASTERROR, OnGetvcdlasterror)
  95.     ON_BN_CLICKED(IDC_SETVCDDRIVELETTERS, OnSetvcddriveletters)
  96.     ON_BN_CLICKED(IDC_VCDINSERT, OnVcdinsert)
  97.     //}}AFX_MSG_MAP
  98. END_MESSAGE_MAP()
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CVcdAPITestDlg message handlers
  102.  
  103. BOOL CVcdAPITestDlg::OnInitDialog()
  104. {
  105.     CDialog::OnInitDialog();
  106.  
  107.     // Add "About..." menu item to system menu.
  108.  
  109.     // IDM_ABOUTBOX must be in the system command range.
  110.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  111.     ASSERT(IDM_ABOUTBOX < 0xF000);
  112.  
  113.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  114.     if (pSysMenu != NULL)
  115.     {
  116.         CString strAboutMenu;
  117.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  118.         if (!strAboutMenu.IsEmpty())
  119.         {
  120.             pSysMenu->AppendMenu(MF_SEPARATOR);
  121.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  122.         }
  123.     }
  124.  
  125.     // Set the icon for this dialog.  The framework does this automatically
  126.     //  when the application's main window is not a dialog
  127.     SetIcon(m_hIcon, TRUE);            // Set big icon
  128.     SetIcon(m_hIcon, FALSE);        // Set small icon
  129.     
  130.     // TODO: Add extra initialization here
  131.     
  132.     return TRUE;  // return TRUE  unless you set the focus to a control
  133. }
  134.  
  135. void CVcdAPITestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  136. {
  137.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  138.     {
  139.         CAboutDlg dlgAbout;
  140.         dlgAbout.DoModal();
  141.     }
  142.     else
  143.     {
  144.         CDialog::OnSysCommand(nID, lParam);
  145.     }
  146. }
  147.  
  148. // If you add a minimize button to your dialog, you will need the code below
  149. //  to draw the icon.  For MFC applications using the document/view model,
  150. //  this is automatically done for you by the framework.
  151.  
  152. void CVcdAPITestDlg::OnPaint() 
  153. {
  154.     if (IsIconic())
  155.     {
  156.         CPaintDC dc(this); // device context for painting
  157.  
  158.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  159.  
  160.         // Center icon in client rectangle
  161.         int cxIcon = GetSystemMetrics(SM_CXICON);
  162.         int cyIcon = GetSystemMetrics(SM_CYICON);
  163.         CRect rect;
  164.         GetClientRect(&rect);
  165.         int x = (rect.Width() - cxIcon + 1) / 2;
  166.         int y = (rect.Height() - cyIcon + 1) / 2;
  167.  
  168.         // Draw the icon
  169.         dc.DrawIcon(x, y, m_hIcon);
  170.     }
  171.     else
  172.     {
  173.         CDialog::OnPaint();
  174.     }
  175. }
  176.  
  177. // The system calls this to obtain the cursor to display while the user drags
  178. //  the minimized window.
  179. HCURSOR CVcdAPITestDlg::OnQueryDragIcon()
  180. {
  181.     return (HCURSOR) m_hIcon;
  182. }
  183.  
  184. /////////////////////////////////////////////////////////////////////////////
  185.  
  186. void CVcdAPITestDlg::OnGetvcddriveletters() 
  187. //
  188. // Show the existing virtual drive letters
  189. //
  190. {
  191.     char cVcdDrives[27] = "\0";
  192.  
  193.     DWORD dwRC = VCDApiGetVCDDriveLetters(cVcdDrives, 27);
  194.     
  195.     if(dwRC == VCD_ERROR_NONE)
  196.     {
  197.         CString strMsg;
  198.         strMsg.Format("Virtual drive letters found: '%s'", cVcdDrives);
  199.         AfxMessageBox(cVcdDrives, MB_OK | MB_ICONINFORMATION);
  200.     }
  201.     else
  202.         ShowVCDError(dwRC);
  203. }
  204.  
  205. /////////////////////////////////////////////////////////////////////////////
  206.  
  207. void CVcdAPITestDlg::OnGetvcdfilefromdrive() 
  208. //
  209. // Shows all virtual drives and the inserted image file names
  210. //
  211. {
  212.     char cVcdDrives[27] = "\0";
  213.  
  214.     DWORD dwRC = VCDApiGetVCDDriveLetters(cVcdDrives, 27);
  215.     
  216.     if(dwRC == VCD_ERROR_NONE)
  217.     {
  218.         CString strMsg;
  219.         CString strLine;
  220.         char cVCDFilename[MAX_PATH];
  221.         int iLen = strlen(cVcdDrives);
  222.  
  223.         for(int i = 0; i < iLen && dwRC == VCD_ERROR_NONE; i++)
  224.         {
  225.             dwRC = VCDApiGetMountedFileFromDrive(cVcdDrives[i], cVCDFilename, MAX_PATH);
  226.  
  227.             if(dwRC == VCD_ERROR_NONE)
  228.             {
  229.                 if(! strMsg.IsEmpty())
  230.                     strMsg += "\n";
  231.  
  232.                 strLine.Format("%C:\t= %s", cVcdDrives[i], (strlen(cVCDFilename) > 0 ? cVCDFilename : "<Empty drive>"));
  233.                 strMsg += strLine;
  234.             }
  235.         }
  236.     
  237.         if(dwRC == VCD_ERROR_NONE)
  238.         {
  239.             if(strMsg.IsEmpty())
  240.                 AfxMessageBox("No virtual drives found!", MB_OK | MB_ICONINFORMATION);
  241.             else
  242.                 AfxMessageBox(strMsg, MB_OK | MB_ICONINFORMATION);
  243.         }
  244.     }
  245.  
  246.     if(dwRC != VCD_ERROR_NONE)
  247.         ShowVCDError(dwRC);
  248. }
  249.  
  250. /////////////////////////////////////////////////////////////////////////////
  251. void CVcdAPITestDlg::OnVcdinsert() 
  252. //
  253. // Insert a virtual CD into the first available virtual drive
  254. //
  255. {
  256.     CDlgAskVCD dlg;
  257.  
  258.     if(dlg.DoModal() == IDOK)
  259.     {
  260.         char cVcdDrives[27] = "\0";
  261.  
  262.         DWORD dwRC = VCDApiGetVCDDriveLetters(cVcdDrives, 27);
  263.         
  264.         if(dwRC == VCD_ERROR_NONE)
  265.         {
  266.             dwRC = VCDApiInsert(cVcdDrives[0], dlg.m_strVCDFilename, "");
  267.  
  268.             if(dwRC == VCD_ERROR_NONE)
  269.             {
  270.                 CString strMsg;
  271.                 strMsg.Format("'%s' inserted into virtual drive %C:", dlg.m_strVCDFilename, cVcdDrives[0]);
  272.                 AfxMessageBox(strMsg, MB_OK | MB_ICONINFORMATION);
  273.             }
  274.         }
  275.  
  276.         if(dwRC != VCD_ERROR_NONE)
  277.             ShowVCDError(dwRC);
  278.     }    
  279. }
  280.  
  281. /////////////////////////////////////////////////////////////////////////////
  282.  
  283. void CVcdAPITestDlg::OnVcdeject() 
  284. //
  285. // Eject all virtual CDs
  286. //
  287. {
  288.     AfxMessageBox("Eject all virtual CDs", MB_OK | MB_ICONINFORMATION);
  289.     
  290.     char cVcdDrives[27] = "\0";
  291.  
  292.     DWORD dwRC = VCDApiGetVCDDriveLetters(cVcdDrives, 27);
  293.     
  294.     if(dwRC == VCD_ERROR_NONE)
  295.     {
  296.         char cVCDFilename[MAX_PATH];
  297.         char cDrv[2];
  298.         int iLen = strlen(cVcdDrives);
  299.  
  300.         cDrv[1] = '\0';
  301.  
  302.         for(int i = 0; i < iLen && dwRC == VCD_ERROR_NONE; i++)
  303.         {
  304.             dwRC = VCDApiGetMountedFileFromDrive(cVcdDrives[i], cVCDFilename, MAX_PATH);
  305.  
  306.             if(strlen(cVCDFilename) > 0 && dwRC == VCD_ERROR_NONE)
  307.             {
  308.                 cDrv[0] = cVcdDrives[i];
  309.                 dwRC = VCDApiEject(cDrv);
  310.             }
  311.         }
  312.     }
  313.  
  314.     if(dwRC != VCD_ERROR_NONE)
  315.         ShowVCDError(dwRC);
  316. }
  317.  
  318. /////////////////////////////////////////////////////////////////////////////
  319.  
  320. void CVcdAPITestDlg::OnSetvcddriveletters() 
  321. //
  322. // set virtual drive letters
  323. //
  324. {
  325.     char cVcdDrives[27] = "\0";
  326.  
  327.     DWORD dwRC = VCDApiGetVCDDriveLetters(cVcdDrives, 27);
  328.     
  329.     if(dwRC == VCD_ERROR_NONE)
  330.     {
  331.         CDlgSetDrives dlg;
  332.         dlg.m_strDrives = cVcdDrives;
  333.  
  334.         if(dlg.DoModal() == IDOK)
  335.         {
  336.             if(dlg.m_strDrives.IsEmpty())
  337.                 AfxMessageBox("There must be at least 1 virtual drive!\nOperation stopped.", MB_OK | MB_ICONSTOP);
  338.             else
  339.             {
  340.                 BeginWaitCursor();
  341.                 dwRC = VCDApiSetDriveLetters(dlg.m_strDrives);
  342.                 EndWaitCursor();
  343.             
  344.                 if(dwRC == VCD_ERROR_NONE)
  345.                 {
  346.                     CString strMsg;
  347.                     strMsg.Format("Virtual drive letters changed : '%s'", dlg.m_strDrives);
  348.                     AfxMessageBox(strMsg, MB_OK | MB_ICONINFORMATION);
  349.                 }
  350.             }
  351.         }
  352.     }
  353.  
  354.     if(dwRC != VCD_ERROR_NONE)
  355.         ShowVCDError(dwRC);
  356. }
  357.  
  358. /////////////////////////////////////////////////////////////////////////////
  359.  
  360. void CVcdAPITestDlg::OnGetvcdlasterror() 
  361. //
  362. // Show the last error from the Virtual CD API
  363. // 
  364. {
  365.     ShowVCDError(VCDApiGetLastError());    
  366. }
  367.  
  368. /////////////////////////////////////////////////////////////////////////////
  369.  
  370. void CVcdAPITestDlg::OnVcddebug() 
  371. //
  372. // if active and an error happens in the API, dialogs pop up and show
  373. // additional debug information
  374. //
  375. {
  376.     UpdateData(TRUE);
  377.     VCDApiSetDebug(m_bVCDDebug);
  378. }
  379.  
  380. /////////////////////////////////////////////////////////////////////////////
  381.  
  382. void CVcdAPITestDlg::ShowVCDError(DWORD dwRC)
  383. //
  384. // Display Virtual CD API error
  385. //
  386. {
  387.     CString strMsg;
  388.     strMsg.Format("Virtual CD API error - EC %d!", dwRC);
  389.     AfxMessageBox(strMsg, MB_OK | MB_ICONSTOP);
  390. }
  391.  
  392. /////////////////////////////////////////////////////////////////////////////
  393.